/* 
 * AP(r) Computer Science GridWorld Case Study:
 * Copyright(c) 2005-2006 Cay S. Horstmann (http://horstmann.com)
 *
 * This code is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * @author Chris Nevison
 * @author Barbara Cloud Wells
 * @author Cay Horstmann
 */
import info.gridworld.actor.Actor;
import info.gridworld.grid.Location;
import info.gridworld.grid.Grid;

import java.util.ArrayList;

public final class ChameleonKid extends ChameleonCritter {
	public ChameleonKid() {
		// TODO Auto-generated constructor stub
	}

	public ArrayList<Actor> getActors() {
		// TODO Auto-generated method stub
		ArrayList<Actor> actors = new ArrayList<Actor>();
		ArrayList<Location> locs = new ArrayList<Location>();

		Grid grid = getGrid();
		Location loc = getLocation();

		// 前方向
		Location neighborLoc = loc.getAdjacentLocation(getDirection());
		if (grid.isValid(neighborLoc)) {
			locs.add(neighborLoc);
		}

		// 后方向
		neighborLoc = loc.getAdjacentLocation(getDirection() + 180);
		if (grid.isValid(neighborLoc)) {
			locs.add(neighborLoc);
		}
		for (Location l : locs) {
			Actor actor = getGrid().get(l);
			if (actor != null) {
				actors.add(actor);
			}
		}
		return actors;
	}
}
